package com.kethink;

import java.util.Arrays;

/**
 * @Description create by xuxiaojun
 * date: 2018/12/26
 * Time: 17:31
 */
public class LeeCode_824 {

    public static String toGoatLatin(String S) {

        String[] array = S.split(" ");
        StringBuilder result = new StringBuilder("");
        for(int i = 0 ; i < array.length ; i++){
            //结果中的空格
            if(i >= 1){
                result.append(" ");
            }
            //每个单词后面的i个a
            StringBuilder str = new StringBuilder("");
            int j = i;
            while (j>=0){
                str.append("a") ;
                j--;
            }
            //判断是否是元音字符开头（包括大小写）
            String s = array[i];
            if(s.startsWith("a")||s.startsWith("e")||s.startsWith("i")||s.startsWith("o")||s.startsWith("u")
                    ||s.startsWith("A")||s.startsWith("E")||s.startsWith("I")||s.startsWith("O")||s.startsWith("U")){
                    result.append(s);
            }else{
                char c = s.charAt(0);

                result.append(s.substring(1,s.length()) + c );
            }
            result.append("ma").append(str);
        }
        return result.toString();
    }
    public static void main(String[] args){
        String S = "I speak Goat Latin";
        System.out.println(toGoatLatin(S));
    }

}
